package com.jy.service.filemanager.project;

import java.util.ArrayList;
import java.util.List;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jy.entity.filemanager.TSProject;
import com.jy.repository.filemanager.ProjectDao;
import com.jy.service.base.BaseServiceImp;
import com.jy.task.utils.TaskOperLogUtil;

@Service("projectService")
public class ProjectServiceImp extends BaseServiceImp<TSProject> implements
		ProjectService {

	/** 调度工厂Bean */
	@Autowired
	private Scheduler scheduler;

	@Override
	@Transactional
	public int creatProject(TSProject o) {
		int res = 0;
		try {
			// o.setCreateDate(new Date());
			// 更新数据库
			TaskOperLogUtil.saveTaskLog(1, "项目", "新增项目信息");
			super.insert(o);
			res = 1;
		} catch (Exception e) {
			logger.error("创建任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public int updateProject(TSProject o) {
		int res = 0;
		try {
			ProjectDao dao = (ProjectDao) baseDao;
			TaskOperLogUtil.saveTaskLog(2, "项目", "修改项目信息");
			// 从数据库查找原信息
			dao.updateProject(o);
			res = 1;
		} catch (Exception e) {
			logger.error("创建任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public int deleteProject(TSProject o) {
		int res = 0;
		try {
			ProjectDao dao = (ProjectDao) baseDao;
			// 从数据库查找原信息
			dao.deleteProject(o);
			TaskOperLogUtil.saveTaskLog(3, "项目", "删除项目信息");
			res = 1;
		} catch (Exception e) {
			logger.error("删除任务失败", e);
		}
		return res;
	}

	@Override
	@Transactional
	public TSProject findProjectById(TSProject o) {
		ProjectDao dao = (ProjectDao) baseDao;
		// 从数据库查找原信息
		dao.findProjectByPId(o.getId());
		return o;
	}

	@Override
	@Transactional
	public List<TSProject> getProListByName(String name) {
		List<TSProject> objList = new ArrayList<TSProject>();
		try {
			ProjectDao dao = (ProjectDao) baseDao;
			// 从数据库查找原信息
			objList = dao.getProductListByName(name);
		} catch (Exception e) {
			logger.error("删除任务失败", e);
		}
		return objList;
	}
}
